#ifndef JSONRCPMESSAGESERIALIZER_H
#define JSONRCPMESSAGESERIALIZER_H

#include "IProtocolHandler.h"
#include <QJsonDocument>

/**
 * @brief JSON-RPC message serializer implementation
 * @details Serializes JSON-RPC responses and notifications according to JSON-RPC 2.0 specification
 */
class JsonRpcMessageSerializer : public IMessageSerializer
{
public:
    explicit JsonRpcMessageSerializer();
    ~JsonRpcMessageSerializer() override = default;

public:// IMessageSerializer
    QJsonObject serializeSuccessResponse(const QVariant& id, const QJsonObject& result) override;
    QJsonObject serializeErrorResponse(const QVariant& id, int errorCode, const QJsonValue& errorData = QJsonValue()) override;
    QJsonObject serializeNotification(const QString& method, const QJsonObject& params) override;
    QByteArray toByteArray(const QJsonObject& jsonObject) override;

private:
    /**
     * @brief Create standardized error object.
     * Constructs a JSON-RPC compliant error object with the specified
     * error code, message, and optional data. This follows the JSON-RPC 2.0
     * error object specification.
     * @param code - Error code (standard JSON-RPC or custom)
     * @param message - Human-readable error message
     * @param data - Optional additional error data (default: QJsonValue())
     * @return QJsonObject - Structured error object
     */
    QJsonObject createErrorObject(int code, const QString& message, const QJsonValue& data = QJsonValue()) const;
    
};

#endif // JSONRCPMESSAGESERIALIZER_H
